//============================================================================
// Name        : ServerConnection.h
// Author      : Jonathan Ellithorpe and Allen Lee
// Version     :
// Copyright   : UC Berkeley
// Description : The ServerConnection class handles accepting a single connection
//	and receiving everything on that connection until it is closed (and storing
//	all received information in a file specified by a file descriptor). This class
//	abstracts away all the details of sliding windows and ack sending.
//============================================================================

#ifndef SERVERCONNECTION_H_
#define SERVERCONNECTION_H_

#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <signal.h>
#include <regex.h>
#include <string.h>
#include "stdGNUTDefs.h"
#include "ReceiveWindow.h"
#include "Packet.h"

class ServerConnection
{
private:
	struct sockaddr_in myAddr;
	struct sockaddr_in dstAddr;
	socklen_t dstAddrLen;
	int yes;
	
	ReceiveWindow myRcvWindow;
	
	int fdSend;
	int fdRecv;
	int myBytesRcvd;
	int myMsgBufLen;
	char* myMsgBuf;
	Packet myRcvdPacket;
	Packet myAckPacket;
	

public:
	ServerConnection(int port, int wndw);
	virtual ~ServerConnection();
	
	int accept();
	int recv(int fd);
	int sendPacket(Packet p);
	void closeConnection();
};

#endif /*SERVERCONNECTION_H_*/
